package demo.IOInputOutput;

import java.io.*;
import java.util.Arrays;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/12-08-12-11:29
 * @Description：demo.IOInputOutput   字符输入输出流
 */
/*
Reader

Writer

字符数组输入输出流
字符文件输入输出流
 */
public class CharStream {
    public static void main(String[] args) {
        //1、声明并创建流
        char[] origin = "hello world".toCharArray();
        CharArrayReader reader = new CharArrayReader(origin);
        CharArrayWriter writer = new CharArrayWriter();     //内置数组（内置流向）

        //2、使用流
        char[] temp = new char[1024];
        int len = -1;
        try {
            while ((len = reader.read(temp)) != -1){
                writer.write(temp,0,len);
            }
            char[] value = writer.toCharArray();
            System.out.println(Arrays.toString(value));
            System.out.println(new String(value));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //3、关闭流
            reader.close();
            writer.close();
        }
    }
}
